package com.bnyy.message.bean.chat.message_data;

import com.bnyy.message.enums.MessageType;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;

import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2023/1/9
 **/
@Table(name = "message_notice_goods")
public class NoticeGoodsMessage extends MessageData {

    public enum GoodsType implements Serializable {
        UNKNOWN(-1), NORMAL(1), GROUP_PURCHASE(2), SERVICE(3);

        int type;

        GoodsType(int type) {
            this.type = type;
        }

        public int getType() {
            return type;
        }

        public static GoodsType getGoodsType(int i) {
            for (GoodsType type : values()) {
                if (type.getType() == i) {
                    return type;
                }
            }
            return UNKNOWN;
        }
    }

    public interface ColumnName {
        String ID = "id";
        String TYPE = "type";
        String USE_DESC = "use_desc";
        String TITLE = "title";
        String TAG_NAME = "tag_name";
        String TAG_COLOR = "tag_color";
        String TAG_BG_COLOR = "tag_bgcolor";
        String GOODS_LIST = "goods_list";
    }

    @Column(name = ColumnName.ID)
    private int id;
    @Column(name = ColumnName.TITLE)
    private String title;
    @Column(name = ColumnName.TYPE)
    private int type;
    @Column(name = ColumnName.USE_DESC)
    private String use_desc;
    @Column(name = ColumnName.TAG_NAME)
    private String tag_name;
    @Column(name = ColumnName.TAG_COLOR)
    private String tag_color;
    @Column(name = ColumnName.TAG_BG_COLOR)
    private String tag_bgcolor;
    @Column(name = ColumnName.GOODS_LIST)
    private String goodsJson;

    @SerializedName("goods_list")
    private ArrayList<GoodsMessage> goodsMessages;

    public NoticeGoodsMessage() {
    }

    public NoticeGoodsMessage(String msgId, JsonObject jsonObject) {
        super(msgId, jsonObject);

        this.id = jsonObject.get("id").getAsInt();
        this.title = jsonObject.get("title").getAsString();
        this.type = jsonObject.get("type").getAsInt();
        this.use_desc = jsonObject.get("use_desc").getAsString();
        this.tag_name = jsonObject.get("tag_name").getAsString();
        this.tag_color = jsonObject.get("tag_color").getAsString();
        this.tag_bgcolor = jsonObject.get("tag_bgcolor").getAsString();
        this.goodsJson = new Gson().toJson(jsonObject.get("goods_list"));
    }

    public int getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public int getType() {
        return type;
    }

    public String getUse_desc() {
        return use_desc;
    }

    public String getTag_name() {
        return tag_name;
    }

    public String getTag_color() {
        return tag_color;
    }

    public String getTag_bgcolor() {
        return tag_bgcolor;
    }

    public String getGoodsJson() {
        return goodsJson;
    }

    public void setGoodsJson(String goodsJson) {
        this.goodsJson = goodsJson;
    }

    public ArrayList<GoodsMessage> getGoodsMessages() {
        return goodsMessages;
    }

    public GoodsType getGoodsType() {
        return GoodsType.getGoodsType(type);
    }

    @Override
    public MessageType getMessageType() {
        return MessageType.NOTICE_GOODS;
    }
}
